package training_camp.day5.leetcode202;

import java.util.HashMap;

class Solution {
    public boolean isHappy(int n) {
        HashMap<Integer, Boolean> booleanHashMap = new HashMap<>();

        while (n != 1 && !booleanHashMap.containsKey(n)) {

            booleanHashMap.put(n, true);
            n = getNumber(n);
        }
        return n == 1;

    }

    private int getNumber(int n) {
        int res = 0;
        while (n > 0) {
            int temp = n % 10;
            res += temp * temp;
            n = n / 10;
        }
        return res;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.isHappy(19);
    }
}
